package com.leyuangame.core.controller.api.user;

import com.leyuangame.core.controller.bean.ResponseHandler.LeYuanResult;
import com.leyuangame.core.service.LoginService;
import com.leyuangame.core.service.UserService;
import com.leyuangame.utils.ExceptionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 获取用户保险箱状态信息
     * @param token
     * @return
     */
    @PostMapping(value = "/rest/user/getUserSafeStatus",produces = "application/json")
    @ResponseBody
    public LeYuanResult login(String token){
        try {
            return userService.getUserSafeStatus(token);
        }catch (Exception e){
            return new LeYuanResult().build(1, ExceptionUtil.getStackTrace(e));
        }
    }

    /**
     * 更新用户保险箱密码
     * @param token
     * @param passwd
     * @param oldPasswd
     * @return
     */
    @PostMapping(value = "/rest/user/updateUserSafePasswd",produces = "application/json")
    @ResponseBody
    public LeYuanResult login(String token,String passwd,String oldPasswd){
        try {
            return userService.updateUserSafePasswd(token,oldPasswd,passwd);
        }catch (Exception e){
            return new LeYuanResult().build(1, ExceptionUtil.getStackTrace(e));
        }
    }

    @PostMapping(value = "/rest/user/getUserSafeLog",produces = "application/json")
    @ResponseBody
    public LeYuanResult login(String token,int type){
        try {
            return userService.getUserSafeLog(token,type);
        }catch (Exception e){
            return new LeYuanResult().build(1, ExceptionUtil.getStackTrace(e));
        }
    }

    @GetMapping(value = "/rest/user/getUserInfoByToken",produces = "application/json")
    @ResponseBody
    public LeYuanResult getUserInfo(String token){
        try {
            return userService.getUserInfoByToken(token);
        }catch (Exception e){
            return new LeYuanResult().build(1, ExceptionUtil.getStackTrace(e));
        }
    }
}
